package com.cg.design.graphicdesignpattern.abstractfactory.listfactory;

import com.cg.design.graphicdesignpattern.abstractfactory.factory.Item;
import com.cg.design.graphicdesignpattern.abstractfactory.factory.Tray;

import java.util.Iterator;

/**
 * 具体的零件：ListTray类，先使用<li>标签输出标题，接着使用<ul>和<li>标签输出每个Item
 *
 * @program: LeetCode->ListTray
 * @description: 具体的零件：ListTray类，先使用<li>标签输出标题，接着使用<ul>和<li>标签输出每个Item
 * @author: cg
 * @create: 2022-03-21 23:41
 **/
public class ListTray extends Tray {
    public ListTray(String caption) {
        super(caption);
    }

    @Override
    public String makeHTML() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("<li>\n");
        buffer.append(caption + "\n");
        buffer.append("<ul>\n");
        Iterator<Item> iterator = tray.iterator();
        while (iterator.hasNext()) {
            Item item = iterator.next();
            buffer.append(item.makeHTML());
        }
        buffer.append("</ul>\n");
        buffer.append("</li>\n");
        return buffer.toString();
    }
}
